
  
  #ifndef __SCALP_BINDER__
  #define __SCALP_BINDER__
  
  namespace scalp {
  
    struct TNil {};
    template<typename H, typename T> struct TListCons { };
    struct TList0 { typedef TNil type; };
    
    template<int K, typename L> struct TListGet;
    template<typename H, typename T> struct TListGet<0, TListCons<H, T> > { typedef H type; };
    template<int K, typename H, typename T> struct TListGet<K, TListCons<H, T> > { typedef typename TListGet<K-1, T>::type type; };
    
    template<typename L> struct TTuple;
    template<> struct TTuple<TNil> { };
    
    template<int K> struct TPlaceholder { };
    static TPlaceholder<0> Free1;
    static TPlaceholder<1> Free2;
    static TPlaceholder<2> Free3;
    static TPlaceholder<3> Free4;
    static TPlaceholder<4> Free5;
    static TPlaceholder<5> Free6;
    static TPlaceholder<6> Free7;
    static TPlaceholder<7> Free8;

    template<int N, typename RetType, typename T, typename BindList>
    struct TBinder;
    

   
   template<typename T>
   struct TBinderField
    	{
    	typedef T type;
    	};

   
   template<typename T>
   struct TRef
	   {
	   T* iPtr;
	   explicit TRef(T& aRef) : iPtr(&aRef) {}
	   operator T& () { return *iPtr; }
	   };

   template<typename T>
   TRef<T> Ref(T& aRef)
	   {
	   return TRef<T>(aRef);
	   };
    

#include "BinderBody.h"

    template<typename A, typename T> A& ApplyPlaceholder(A& aA, T& ) { return aA; }

    
    template<int K, typename TT> typename TTupleGetType<TT, K>::type
    ApplyPlaceholder(TPlaceholder<K>& aPlaceholer, TT& aTuple) { return aTuple.Get(aPlaceholer); }
    

    template<typename TT, int N, typename RetType, typename T, typename BindList>
    RetType ApplyPlaceholder(TBinder<N, RetType, T, BindList>& aA, TT& aTuple)
    	{
    	return aA.CallByTuple(aTuple);
    	}
    
    template<typename RetType>
    TBinder<0, RetType, TNil, TNil>
    Bind(RetType(*aTarget) ())
    {
      return 
    TBinder<0, RetType, TNil, TNil >
    (aTarget);
    }
    
    
    } // namespace scalp
    #endif // __SCALP_BINDER__

    
